Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read bat config from multiple config files #691

Closed
wants to merge 4 commits into from

Conversation

goku321
Copy link

@goku321 goku321 commented Oct 15, 2019

Summary

  • Added logic to read bat config from multiple config files.

Fixes: #668

@@ -16,8 +16,22 @@ pub fn config_file() -> PathBuf {
}

pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
let mut config_file_path = vec![PathBuf::from("/etc/bat/config")];
config_file_path.push(default_config_path());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how does that work?

/etc/bat/config is always included but ~/.config/bat/config might be overwritten by BAT_CONFIG_PATH? Is that a good idea?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharkdp Thanks for the review. I'm thinking of moving the logic for getting path from env var BAT_CONFIG_PATH to a separate function (something like get_config_file_path_from_env and default_config_path() will just return ~/.config/bat/config.

let mut config_args = vec![];

for path in config_file_path.iter() {
let args = read_args_from_config_file(path.to_path_buf());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could avoid the .to_path_buf() if read_args_from_config_file simply takes a &Path.

for path in config_file_path.iter() {
let args = read_args_from_config_file(path.to_path_buf());
config_args.append(&mut args.unwrap());
}
Copy link
Owner

@sharkdp sharkdp Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary, but the whole loop could probably be written in functional style with .map(…) and .collect(). This would also avoid the mut on config_args.

Something like (not tested and most probably wrong):

let config_args = config_file_path
  .iter()
  .map(read_args_from_config_file)
  .transpose()?
  .flatten()
  .collect();

@@ -16,8 +16,22 @@ pub fn config_file() -> PathBuf {
}

pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
let mut config_file_path = vec![PathBuf::from("/etc/bat/config")];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config_file_path => config_file_paths?

@sharkdp
Copy link
Owner

sharkdp commented Dec 22, 2019

Going to close this for now, as there is no further feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate system and user config files
2 participants